﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace MyAuthCore.Tools
{
    public class JsonHelper
    {
        /// <summary>
        /// 实体类转换成json字符串
        /// </summary>
        /// <param name="jsonObject"></param>
        /// <returns></returns>
        public static string SerializeObject(object obj)
        {
            try
            {
                return JsonConvert.SerializeObject(obj);
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// json字符串转换为实体类
        /// </summary>
        /// <typeparam name="T">具体类</typeparam>
        /// <param name="jsonString">字符串</param>
        /// <returns></returns>
        public static T DeserializeObject<T>(string json)
        {
            try
            {
                return JsonConvert.DeserializeObject<T>(json);
            }
            catch (Exception ex)
            {
                return default(T);
            }
        }
    }
}
